package com.woniuxy.store.core.service.impl;

import com.woniuxy.store.core.model.MdStorefirst;
import com.woniuxy.store.core.mapper.MdStorefirstMapper;
import com.woniuxy.store.core.model.MdStoresecond;
import com.woniuxy.store.core.model.MdStorethird;
import com.woniuxy.store.core.service.MdStoreService;
import com.woniuxy.store.core.service.MdStorefirstService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.store.core.service.MdStoresecondService;
import com.woniuxy.store.core.vo.MdStoreVo;
import com.woniuxy.store.core.vo.MdStorefirstVo;
import com.woniuxy.store.core.vo.MdStoresecondVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Service
public class MdStorefirstServiceImpl extends ServiceImpl<MdStorefirstMapper, MdStorefirst> implements MdStorefirstService {

    @Autowired(required = false)
    MdStorefirstMapper mdStorefirstMapper;

    @Autowired(required = false)
    MdStoresecondService mdStoresecondService;

    @Override
    public void insertOne(MdStorefirst mdStorefirst) {
        mdStorefirstMapper.insert(mdStorefirst);
    }

    @Override
    public void delectOne(int firstId) {
        mdStorefirstMapper.delectOne(firstId);
    }

    //通过storeid查一级菜单及二级菜单裂变
    @Override
    public List<MdStorefirstVo> listfirstvo(int storeId) {
        List<MdStorefirstVo> listfirstvo=new ArrayList<>();
        List<MdStoresecondVo> listsecondvo=new ArrayList<>();

        List<MdStorefirst> listfirst= mdStorefirstMapper.getFirst(storeId);
        System.out.println("lis1"+listfirst);
        for (int i=0;i<listfirst.size();i++){
            MdStorefirstVo mdStorefirstVo=new MdStorefirstVo();
            MdStorefirst mdStorefirst=listfirst.get(i);
            int firstId=mdStorefirst.getFirstId();
             listsecondvo=mdStoresecondService.listsecondvo(firstId,storeId);
            System.out.println("lis22"+listsecondvo);
             mdStorefirstVo.setMdStorefirst(mdStorefirst);
             mdStorefirstVo.setList(listsecondvo);
//            MdStorefirstVo mdStorefirstVo1=null;
//            mdStorefirstVo1=mdStorefirstVo;
             listfirstvo.add(mdStorefirstVo);
        }
        return listfirstvo;
    }

    @Override
    public List<MdStoresecond> abc(Integer firstId) {
        return mdStorefirstMapper.abc(firstId);
    }

    @Override
    public void delect(int firstId) {
        mdStorefirstMapper.deleteServe(firstId);
    }

    @Override
    public List<MdStorefirst> selectAll() {
        return mdStorefirstMapper.selectAll();
    }
}
